package com.firstsight.micro.homedo.controller;

import com.firstsight.micro.homedo.mq.RocketMQProducer;
import com.firstsight.micro.homedo.service.ILockerService;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.nio.channels.Channel;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author: yanshuchun
 */
@RestController
@Slf4j
public class HomedoController {
    @Autowired
    private ILockerService lockerService;
    @Autowired
    private RocketMQProducer rocketMQProducer;

    @GetMapping("/distributedLock")
    private void distributedLock() {
//        lockerService.synchronizedTest();
//        lockerService.redisTemplateTest();
//        lockerService.redissonClientTest();
        lockerService.redissonClientTryLockTest();
    }
    @GetMapping("/scheduler")
    private void scheduler() {

        Date date = new Date(System.currentTimeMillis() + 1000);
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.get(Calendar.YEAR));
        //默认从0-11
        System.out.println(calendar.get(Calendar.MONTH));
        System.out.println(calendar.get(Calendar.DATE));
        System.out.println(calendar.get(Calendar.HOUR_OF_DAY));
        //12小时制
        //System.out.println(calendar.get(Calendar.HOUR));
        System.out.println(calendar.get(Calendar.MINUTE));
        System.out.println(calendar.get(Calendar.SECOND));

        String cron = calendar.get(Calendar.SECOND)+10 + " "
                +calendar.get(Calendar.MINUTE)+" "
                +calendar.get(Calendar.HOUR_OF_DAY)+" "+calendar.get(Calendar.DATE)+" "+ (calendar.get(Calendar.MONTH)+1) +" "+calendar.get(Calendar.DAY_OF_WEEK)+" "
                +  calendar.get(Calendar.YEAR);


        System.out.println(cron);

//        lockerService.synchronizedTest();
//        lockerService.redisTemplateTest();
//        lockerService.redissonClientTest();
        lockerService.scheduler("19 38 1 24 4 2021-2021");
    }
    @GetMapping("/stop")
    private void stop() {
//        lockerService.synchronizedTest();
//        lockerService.redisTemplateTest();
//        lockerService.redissonClientTest();
        lockerService.stop();
    }

    @GetMapping("channel")
    private void channel(){
    }

    @GetMapping("rocketmq")
    private void rocketmq(){
        rocketMQProducer.sendMsg("test","我是消息体");
    }



}
